//
//  GWMyInputToolBar.m
//  新浪微博
//
//  Created by qianfeng on 16/1/15.
//  Copyright (c) 2016年 高炜. All rights reserved.
//

#import "GWMyInputToolBar.h"

@interface GWMyInputToolBar ()
@property (nonatomic,weak) UIButton *emotionBtn;
@end
@implementation GWMyInputToolBar

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
        self.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageWithName:@"compose_toolbar_background"]];
        [self setToolBar];
    }
    return self;
}
-(void)setToolBar
{
    [self addBtnWithImageName:@"compose_camerabutton_background" highLightImageName:@"compose_camerabutton_background_highlighted" toolBarType:InputToolBarButtonTypeCamera];
    [self addBtnWithImageName:@"compose_toolbar_picture" highLightImageName:@"compose_toolbar_picture_highlighted" toolBarType:InputToolBarButtonTypePicture];
    [self addBtnWithImageName:@"compose_mentionbutton_background" highLightImageName:@"compose_mentionbutton_background_highlighted" toolBarType:InputToolBarButtonTypeMention];
    [self addBtnWithImageName:@"compose_trendbutton_background" highLightImageName:@"compose_trendbutton_background_highlighted" toolBarType:InputToolBarButtonTypeTopic];
   UIButton *emotionBtn = [self addBtnWithImageName:@"compose_emoticonbutton_background" highLightImageName:@"compose_emoticonbutton_background_highlighted" toolBarType:InputToolBarButtonTypeEmotion];
    self.emotionBtn =emotionBtn;
}
-(UIButton *)addBtnWithImageName:(NSString *)imageName highLightImageName:(NSString *)highLightImageName toolBarType:(InputToolBarButtonType)type
{
    UIButton *btn  =[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageWithName:imageName] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageWithName:highLightImageName] forState:UIControlStateHighlighted];
    btn.tag =type;
    [btn addTarget: self action:@selector(btnOnTouch:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    return btn;
}
-(void)btnOnTouch:(UIButton *)btn
{
    if ([self.delegate respondsToSelector:@selector(myToolBar:didClickBtn:)]) {
        [self.delegate myToolBar:self didClickBtn:(int)btn.tag];
    }
}
-(void)layoutSubviews
{
    NSInteger count =self.subviews.count;
    self.frame =CGRectMake(0, self.superview.height-44, self.superview.width, 44);
    [super layoutSubviews];
    CGFloat btnW =self.superview.width/count;
    for (int i =0; i<count; i++) {
        UIButton *btn =self.subviews[i];
        btn.frame =CGRectMake(btnW*i, 0, btnW, 44);
    }
}

-(void)setEmotionKeybord:(BOOL)emotionKeybord
{
    _emotionKeybord =emotionKeybord;
    if (emotionKeybord) {
        [self.emotionBtn setImage:[UIImage imageWithName:@"compose_emoticonbutton_background"] forState:UIControlStateNormal];
        [self.emotionBtn setImage:[UIImage imageWithName:@"compose_emoticonbutton_background_highlighted"] forState:UIControlStateHighlighted];
    }
    else
    {
        [self.emotionBtn setImage:[UIImage imageWithName:@"compose_keyboardbutton_background"] forState:UIControlStateNormal];
        [self.emotionBtn setImage:[UIImage imageWithName:@"compose_keyboardbutton_background_highlighted"] forState:UIControlStateHighlighted];
    }
}
@end
